import wepy from 'wepy'

export default class Home extends wepy.mixin {
  data = {
    // 轮播图的数据
    swiper: [],
    // 分类导航
    navCate: [],
    // 楼层数据
    floorData: []
  }

  config = {
  }

  methods = {
    // 跳转到商品列表
    goGoodsList (url) {
      wepy.navigateTo({url})
    }
  }

  // 获取轮播图数据
  async getSwiper () {
    const {data: res} = await wepy.get('/home/swiperdata')
    if(res.meta.status !== 200) return wepy.baseToast()
    this.swiper = res.message
    this.$apply()
  }

  // 获取首页分类导航数据
  async getCates () {
    const {data: res} = await wepy.get('/home/catitems')
    if(res.meta.status !== 200) return wepy.baseToast()
    this.navCate = res.message
    this.$apply()
  }

  // 获取楼层数据
  async getFloorData () {
    const { data: res } = await wepy.get('/home/floordata')
    if(res.meta.status !== 200) return wepy.baseToast()
    this.floorData = res.message
    this.$apply()
  }

  onLoad () {
    this.getSwiper()
    this.getCates()
    this.getFloorData()
  }

  onShow () {
    this.$parent.setTabbarBadge()
  }
}